package com.bawei.mall.product.controller;

import com.bawei.common.core.domain.R;
import com.bawei.common.core.web.controller.BaseController;
import com.bawei.common.core.web.page.TableDataInfo;
import com.bawei.mall.product.domain.MallProductOrderInfo;
import com.bawei.mall.product.domain.model.OrderModel;
import com.bawei.mall.product.domain.request.OrderRequest;
import com.bawei.mall.product.service.MallProductOrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName MallProductOrderInfoController
 * @Description 描述
 * @Author ZiZheng.Li
 * @Date 2024/7/9 11:51
 */
@RestController
@RequestMapping("/order")
public class MallProductOrderInfoController extends BaseController {
    @Autowired
    private MallProductOrderInfoService mallProductOrderInfoService;

    @GetMapping("/list")
    public TableDataInfo list(@RequestBody MallProductOrderInfo mallProductInfo) {
        startPage();
        List<MallProductOrderInfo> list = mallProductOrderInfoService.list(mallProductInfo);
        return getDataTable(list);
    }


    @PostMapping("/generateConfirmOrder")
    public R<OrderModel> generateConfirmOrder(@RequestBody List<Integer> ids) {
        OrderModel orderModel = mallProductOrderInfoService.generateConfirmOrder(ids);
        return R.ok(orderModel);
    }

    @PostMapping("/generateOrder")
    public R generateOrder(@RequestBody OrderRequest orderRequest) {
        mallProductOrderInfoService.generateOrder(orderRequest);
        return R.ok();
    }
}
